package br.com.divulgaqui.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity implementation class for Entity: Venda
 *
 */
@Entity
@SequenceGenerator(name="vendas_seq", sequenceName="vendas_seq", allocationSize=1)
public class Venda implements Serializable {
	   
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="vendas_seq")
	private Long id;
	
	@Column(nullable=false)	
	@Temporal(TemporalType.TIMESTAMP)
	private Date dataVenda;
	
	@Column(nullable=false)	
	private Double valorTotal;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_pessoa", referencedColumnName="id", nullable=false, insertable=true, updatable=true)
	private Pessoa pessoa;
	
	@OneToMany(mappedBy="venda", fetch=FetchType.LAZY)
	private List<ItemVenda> inItensVenda  = new ArrayList<ItemVenda>();
	
	private static final long serialVersionUID = 1L;

	public Venda() {
		super();
	}   
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}   
	public Date getDataVenda() {
		return this.dataVenda;
	}

	public void setDataVenda(Date dataVenda) {
		this.dataVenda = dataVenda;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Venda other = (Venda) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	public Double getValorTotal() {
		return valorTotal;
	}
	public void setValorTotal(Double valorTotal) {
		this.valorTotal = valorTotal;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public Pessoa getPessoa() {
		return pessoa;
	}
	public void setPessoa(Pessoa pessoa) {
		this.pessoa = pessoa;
	}
	public List<ItemVenda> getInItensVenda() {
		return inItensVenda;
	}
	public void setInItensVenda(List<ItemVenda> inItensVenda) {
		this.inItensVenda = inItensVenda;
	}   
}
